package org.internet.UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ReceiveMessageDemo {
    public static void main(String[] args) throws IOException {
        //1.创建接收端对象
        DatagramSocket ds = new DatagramSocket(10086);

        //2.创建接收端集装箱，接收数据
        byte[] buf = new byte[1024];

        DatagramPacket dp = new DatagramPacket(buf, 0, buf.length);
        //3.接收数据
        ds.setSoTimeout(10000);
        ds.receive(dp);

        System.out.println(11111);
        //4.解析数据
        byte[] data = dp.getData();
        System.out.println(new String(data));
        System.out.println(dp.getPort());
        System.out.println(dp.getLength());
        //5.关闭资源
        ds.close();


    }
}
